//
//  CNdetailsCell.m
//  BeeQuick_19
//
//  Created by 张旭峰 on 16/9/23.
//  Copyright © 2016年 CN Team. All rights reserved.
//

#import "CNdetailsCell.h"
@interface CNdetailsCell ()
@property (weak, nonatomic) IBOutlet UILabel *marketPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *specificsLabel;
;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

@end

@implementation CNdetailsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

-(void)setModel:(CNdetailsModel *)model
{
    _count = _model.count;
    
    _model = model;
    
    self.count = model.count;
    
    self.nameLabel.text = model.name;
    
    self.priceLabel.text = [NSString stringWithFormat:@"¥%.2f",model.price];
    
    
    self.specificsLabel.text = model.specifics;
    self.marketPriceLabel.text = [NSString stringWithFormat:@"¥%.2f",model.market_price];
    
    [self.imgImageView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"v2_placeholder_square"]];
    //    _model.count = _count;
}

- (IBAction)reduceClick:(id)sender {
    
    [[NSNotificationCenter defaultCenter]postNotificationName: CNShopCarBuyNumberDidChangeNotification object:nil];
    if (_model.count > 0) {
        
        self.count = _model.count;
        self.count--;
        NSLog(@"----->123");

        
    }else{
        
        self.count = 0;
        self.count --;
       // _model.count = self.count;
        NSLog(@"----->456");

    }
    
    _model.count = self.count;
    
        //    NSLog(@"减法里%@--->%zd",self.model,self.count);
        
        if ([self.delegate respondsToSelector:@selector(descressCountWithCell:model:)]) {
            
            [self.delegate descressCountWithCell:self model:self.model];
        }
    
    NSLog(@"----->1");
    

}
    
- (IBAction)increaseClick:(id)sender {
      [[NSNotificationCenter defaultCenter]postNotificationName: CNShopCarBuyNumberDidChangeNotification object:nil];
    if (_model.count > 0) {

        self.count = _model.count;
        self.count++;

    }else{
        
        self.count = 0;
        self.count ++;

        
    }
    
    _model.count = self.count;
    if ([self.delegate respondsToSelector:@selector(addCountWithCell:model:poin:frame:)]) {
        
        UIWindow *win = [UIApplication sharedApplication].keyWindow;
        CGPoint start = [self convertPoint:self.imgImageView.center toView:win];
        [self.delegate addCountWithCell:self model:self.model poin:start frame:self.imgImageView.frame];

    }

}
-(void)setCount:(NSInteger)count
{
    _count = count;
    
    if (count > 0) {
        _reduceButton.hidden = NO;
        _countLabel.hidden = NO;
        
        _countLabel.text = [NSString stringWithFormat:@"%zd",_count];
        
        
        
    }else{
        _reduceButton.hidden = YES;
        _countLabel.hidden = YES;
        // _countLabel.text = @(count).description;
        
    }


}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
}

@end
